package com.weng.platform.apiManager.doc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.weng.framework.core.model.ResponseData;
import com.weng.framework.dao.mybatis.model.page.PageModel;
import com.weng.framework.dao.mybatis.service.BaseServiceImpl;
import com.weng.platform.apiManager.doc.entity.DocTemplate;
import com.weng.platform.apiManager.doc.mapper.DocTemplateMapper;
import com.weng.platform.apiManager.doc.service.IDocTemplateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Arrays;


/**
 * api文档模板 服务实现类
 *
 * @author wengzhonghui
 * @date 2020-09-25 18:40:15
 *
 */ 
@Slf4j
@Service
public class DocTemplateServiceImpl extends BaseServiceImpl<DocTemplateMapper, DocTemplate> implements IDocTemplateService {
	@Autowired
	private DocTemplateMapper docTemplateMapper;
	

	/**
	 * 分页查询api文档模板
	 * @return
	 */
	@Override
	public IPage<DocTemplate> list(Integer pageNo,Integer pageSize) {
		QueryWrapper<DocTemplate> qw = new QueryWrapper<>();
		IPage<DocTemplate> page = new PageModel<>(pageNo,pageSize);
		return docTemplateMapper.selectPage(page,qw);
	}


	/**
	 * 获取单个api文档模板
	 * @param id
	 * @return
	 */
	@Override
	public DocTemplate getById(Serializable id) {
		return super.getById(id);
	}

	/**
	 * 新增单个api文档模板
	 * @param docTemplate
	 * @return
	 */
	@Override
	public DocTemplate add(DocTemplate docTemplate)  {
		
		docTemplateMapper.insert(docTemplate);
		return docTemplate;
	}

	/**
	 * 更新单个api文档模板
	 * @param docTemplate
	 * @return
	 * @
	 */
	@Override
	public int update(DocTemplate docTemplate)  {
		
		return docTemplateMapper.updateById(docTemplate);

	}


	@Override
	public ResponseData removeByIds(String ids) {
		String[] docTemplateIds = ids.split(",");
		boolean flag = this.removeByIds(Arrays.asList(docTemplateIds));
		if (flag) {
			return ResponseData.success();
		} else {
			return ResponseData.success();
		}
	}

}
